#ifndef PLAYERWIDGET_H
#define PLAYERWIDGET_H

#include <QWidget>
#include "LitePlayer.h"
#include <memory>


typedef std::shared_ptr< av::LitePlayer >   LitePlayerPtr;


namespace Ui {
class PlayerWidget;
}

class PlayerWidget : public QWidget , public av::MediaEventSink
{
    Q_OBJECT

public:
    struct Tax
    {
        QString date;
        QString time;
        QString QDH;
        QString SJH;
        QString checi;
        QString speed;
        QString LCGYL;
        QString GLB;
        QString JCGK;
    };

public:
    explicit PlayerWidget(QWidget *parent = 0);
    ~PlayerWidget();

    bool checked() const;

    void setChecked(bool checked);

    int index() const;
    void setIndex(int index);

    bool open(const QString& filepath);
    void close();
    bool isOpen();

    void pause();
    void play();
    bool isPaused();
    void togglePlay();

    QString getFilepath() const;

    int getDuration();

    int getState();

    bool seek(int offset);
    bool seekPos(float pos);

    int getTime();

    float getPos();

    bool snap(const QString& filepath);

    void fast();

    void slow();

    float getScale();

    bool getMeta(const std::string& key, QString& value);
	bool getMeta(const std::string& key, int& value);

    bool isMediaEnd();

signals:
    void clicked(int index);
    void rclicked(int index);
    void dbclicked(int index);

    void snapped(int index, const QString& filename);

    void mediaEnd(int index);

    void dragDropped(int index, const QString& url, const QString& id, const QString& name);

protected:
    virtual void paintEvent(QPaintEvent *);
    virtual void mousePressEvent(QMouseEvent * event);
    virtual void mouseDoubleClickEvent(QMouseEvent *event);
    virtual void dragEnterEvent(QDragEnterEvent *event);
    virtual void dragMoveEvent(QDragMoveEvent *event);
    virtual void dropEvent(QDropEvent *event);

protected:
    virtual void onMediaEvent(av::LitePlayer* player, int type, int64_t value);

private:
    Ui::PlayerWidget *ui;

    bool    m_checked;
    int     m_index;

    LitePlayerPtr   m_player;
    QString         m_filepath;
    QString         m_snapFileName;
    bool            m_isMediaEnd;

};

#endif // PLAYERWIDGET_H
